package com.example.smsreceiver;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText editText;
    private ImageView imageView;
    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 获取button 对象
        Button button1 = (Button) findViewById(R.id.button1);
        Button button2 = (Button) findViewById(R.id.button2);
        // 获取EditText 对象
        editText = (EditText) findViewById(R.id.edit_text);
        imageView = (ImageView) findViewById(R.id.imageView);
        progressBar = (ProgressBar) findViewById(R.id.progress_bar);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
    }

    /**
     * 重写了View.OnClickListener  的onClick方法
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button1:
                String inputText = editText.getText().toString();
                Toast.makeText(MainActivity.this, inputText, Toast.LENGTH_LONG).show();

                int progress = progressBar.getProgress();
                progress += 1;
                progressBar.setProgress(progress);
                break;
            case R.id.button2:
                imageView.setImageResource(R.drawable.s2);
                imageView.getResources();
                Toast.makeText(MainActivity.this, "图片修改了" + imageView.getResources() + "::" + imageView.getId() + "::" + R.drawable.s2, Toast.LENGTH_LONG).show();
                // 控制加载动画的显示和隐藏
                if (progressBar.getVisibility() == View.GONE) {
                    progressBar.setVisibility(View.VISIBLE);
                } else {
                    progressBar.setVisibility(View.GONE);
                }
                break;
            default:
                break;
        }
    }
}
